/*
 * FileName: ConsumerDemo.java
 * Author:   zzw
 * Date:     2019年01月15日
 * Description:
 *//*

package com.zzw.rocketmq;

import com.chezhibao.cmq.client.CmqPushConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;

*/
/**
 * 〈〉<br>
 * 〈〉
 *
 * @author zzw
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本]（可选）
 *//*

public class ConsumerDemo {

    public static void main(String[] args) throws MQClientException {
        new DefaultMQPushConsumer();
        CmqPushConsumer consumer = new CmqPushConsumer("retry");
        consumer.setNamesrvAddr("172.28.4.11:9876");
        consumer.setInstanceName(UUID.randomUUID().toString());
        consumer.subscribe("retry", "*");
        consumer.registerMessageListener(new MessageListenerOrderly() {

            @Override
            public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
                for (MessageExt messageExt:msgs) {
                    try {
                        System.out.println(new String(messageExt.getBody()));
                        int i = 1 / 0;
                    } catch (Exception e) {
                        if (messageExt.getReconsumeTimes() < 3) {
                            return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
                        }
                        e.printStackTrace();
                    }
                }
                return ConsumeOrderlyStatus.SUCCESS;
            }
        });
        consumer.start();
    }

    public static Serializable objectDeserialize(byte[] bytes) throws IOException, ClassNotFoundException {
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bais);
        ois.close();
        bais.close();
        return (Serializable) ois.readObject();
    }
}
*/
